<?php
namespace App\Services;
use App\Models\MotionModel;

class MotionService{
	/**
	 * 获取观看记录总数列表
	 * @param int $member_id
	 * @param int $course_id
	 * @return int $watched_id
	 */
	public function getMotionNum($member_id,$course_id){
		$watched_id = MotionModel::where('member_id',$member_id)->where('curriculum_id',$course_id)->select('id')->count();
		return $watched_id;
	}

	/**
	 * 获取锻炼记录列表
	 * @param int $member_id
	 * @return object $motionlist
	 */
	public function getMotionList($member_id){
		$motionlist = MotionModel::orderBy('watch_date','desc')->where('member_id',$member_id)->select('curriculum_id','curriculum_content_id','member_id','watch_date')->get()->toArray();
		if(empty($motionlist)){
		    return false;
        }
		return $motionlist;
	}

	/**
	 * 插入锻炼记录
	 * @param array $data
	 * @return bool $res
	 */
	public function insertMotion($data){
		$res = MotionModel::insert($data);
		return $res;
	}

	/**
	 * 获取视频观看记录
	 * @param int $member_id
	 * @param int $curriculum_id
	 * @param int $curriculum_content_id
	 * @return object $info
	 */
	public function getMotionInfo($member_id,$curriculum_id,$curriculum_content_id){
		$info = MotionModel::where('member_id',$member_id)->where('curriculum_id',$curriculum_id)->where('curriculum_content_id',$curriculum_content_id)->first();
		return $info;
	}
}